package com.kevin.thread;

/**
 * 守护线程
 * 主线程也属于用户线程
 * 用户线程全部结束，守护线程结束
 */
public class DaemonThreadTest {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new DaemonThread());
        thread.setDaemon(true);
        thread.start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("当前线程是："+Thread.currentThread().getName());
            }
        }).start();
        Thread.sleep(2000);
        System.out.println("当前线程是："+Thread.currentThread().getName());

    }
}

class DaemonThread implements Runnable{

    @Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("当前线程是："+Thread.currentThread().getName());
    }
}
